package com.ynhenc.pta.routeRank.impl;

import java.util.*;

import com.ynhenc.comm.NetAddr;
import com.ynhenc.pta.routeRank.*;

public class RouteRequestImpl extends ComLib_PTA implements RouteRequest {

	private RouteRequestImpl() {
	}
	
	public void setSearchRadius( TransitType transitType, double radius ) { 
		this.searchRadiusList.put( transitType, radius);
	}
	
	public double getSearchRadius( TransitType transitType ) {
		Double radius = this.searchRadiusList.get( transitType );
		if( radius == null) {
			return -1;
		} else {
			return radius;
		}
	}

	public void setNaviServer(String hostName, int portNo) {
		RouteRequestImpl.NET_ADDR_NAVI = new NetAddr( hostName, portNo ); 
		
		this.debug( "NaviServer: " + RouteRequestImpl.NET_ADDR_NAVI );
	}
	
	public void setOracleServer( String hostName, int portNo ) {
		RouteRequestImpl.NET_ADDR_ORACLE = new NetAddr( hostName, portNo ); 
		this.debug( "Oracle Server: " + RouteRequestImpl.NET_ADDR_ORACLE );
	}

	public static NetAddr getNaviServerAddr() {
		return RouteRequestImpl.NET_ADDR_NAVI;
	} 
	
	public static NetAddr getOracleServerAddr() {
		return RouteRequestImpl.NET_ADDR_ORACLE;
	}

	public void add(Node node) {
		this.nodeList.add(node);
	}

	public void add(double x, double y, String name) {
		this.add(new Node(x, y, name));
	}

	public int getCountNode() {
		return this.nodeList.size();
	}

	public Node getNode(int index) {
		Vertex vertex = this.nodeList.get(index);
		if (vertex != null && vertex.isNode()) {
			return (Node) vertex;
		} else {
			return null;
		}
	}

	public Node getNodeEnd() {
		return this.nodeList.getEnd();
	}

	public Node getNodeStart() {
		return this.nodeList.getStart();
	}

	public static RouteRequestImpl newRouteRequest() {
		return new RouteRequestImpl();
	}

	public void setBasicTransitType(TransitType basicTransitType) {
		this.basicTransitType = basicTransitType;
	}

	public TransitType getBasicTransitType() {
		return this.basicTransitType;
	}

	public void addTrafficAccidentNode(Node trafficAccidentNode) {
		this.trafficAccidentNode = trafficAccidentNode;
	}

	public boolean isTrafficGood() {
		return this.trafficAccidentNode == null;
	}

	public Scenario getScenario() {
		return scenario;
	}

	public void setScenario(Scenario scenario) {
		this.scenario = scenario;
	}

	public void setEnableDirectConnectCoeff(boolean b) {
		this.enableDirectConnectCoeff = b;
	}
	
	public boolean isEnableDirectConnectCoeff() {
		return this.enableDirectConnectCoeff;
	}

	private Node trafficAccidentNode = null;

	private TransitType basicTransitType = TransitType.WALK;

	private boolean enableDirectConnectCoeff = true;

	private Scenario scenario = ScenarioPta.getScenario();

	private static NetAddr NET_ADDR_NAVI = SysConfPta.NET_ADDR_01_NAVI ;
	private static NetAddr NET_ADDR_ORACLE = SysConfPta.NET_ADDR_02_ORACLE;

	private final NodeList nodeList = new NodeList();
	private final Hashtable< TransitType, Double > searchRadiusList = new Hashtable< TransitType, Double >();

}
